/**
 * StudentListService.java
 * Version 1.0.0
 * Created on 2019年1月17日
 *
 */
package com.yincheng.oes.business.student;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yincheng.oes.business.util.Page;
import com.yincheng.oes.sso.entity.User;
import com.yincheng.oes.sso.mapper.UserMapper;

/**
 * @author yangsy
 * @version 1.0.0
 * @since
 * 创建时间：2019年1月17日
 * <p>
 * 功能描述：
 * <p>
 * 邮箱地址：446948434@qq.com
 */
@Service
public class StudentListService {

    @Autowired
    private StudentListMapper studentListMapper;

    @Autowired
    private UserMapper userMapper;

    private static final String ASSISTANT_ROLE_ID = "4";

    public Pair<Integer, List<QueryResultRowBean>> getListByParam(QueryParamBean param) {
        Page page = param.getPage();
        int total = studentListMapper.countByParam(param);
        page.setTotal(total);
        List<QueryResultRowBean> list = studentListMapper.selectByParam(param);
        return Pair.of(total, list);
    }

    /**
     * 更新学员信息
     *
     * @param param
     */
    public void updateStudentInfo(QueryParamBean param) {
        if (param == null) {
            throw new IllegalArgumentException("updateStudentInfo param is null!");
        }
        if (StringUtils.isEmpty(param.getUserId())) {
            throw new IllegalArgumentException("updateStudentInfo param userId is null!");
        }
        studentListMapper.updateStudentInfoByParam(param);
    }

    public QueryResultRowBean selectByUserId(String userId) {
        if (StringUtils.isEmpty(userId)) {
            throw new IllegalArgumentException("selectByUserId param userId is null!");
        }
        QueryResultRowBean queryResultRowBean = studentListMapper.selectByUserId(userId);
        return queryResultRowBean;
    }

    public List<User> getAssistantList() {
        return userMapper.selectByRoleId(ASSISTANT_ROLE_ID);
    }
}
